package com.jy.rhin.facade.infra.controller.document;

import com.jy.framework.base.entity.Page;
import com.jy.framework.base.entity.Result;
import com.jy.rhin.infra.repo.document.submission.query.DocumentStatisticsQueryHandler;
import com.jy.rhin.sdk.dto.document.statistic.*;
import com.jy.rhin.sdk.feign.client.DocumentStatisticsFeign;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author dhl
 * @date 2022/6/9
 * @Description
 */
@RestController
@RequestMapping("/infra/documentStatistics")
@Api(tags = "文档统计api")
@Slf4j
public class DocumentEntryStatisticsController implements DocumentStatisticsFeign {

    @Resource
    private DocumentStatisticsQueryHandler statisticsQueryHandler;

    @Override
    @ApiOperation("获取文档提交集总数")
    @GetMapping("/querySubmissionSetTotal")
    public Result<Long> querySubmissionSetTotal() {
        return Result.success(statisticsQueryHandler.queryDocumentSetTotal());
    }

    @Override
    @ApiOperation("获取文档总数")
    @GetMapping("/queryDocumentEntryTotal")
    public Result<Long> queryDocumentEntryTotal() {
        return Result.success(statisticsQueryHandler.queryDocumentEntryTotal());
    }

    @Override
    @ApiOperation("获取文档日增数")
    @GetMapping("/queryDocumentEntryTotalByDay")
    public Result<Long> queryDocumentEntryTotalByDay() {
        return Result.success(statisticsQueryHandler.queryDocumentEntryTotalByDay());
    }

    @Override
    @ApiOperation("获取文档指定日期区间每日总数")
    @GetMapping("/queryDocumentEntryTotalGroupDay")
    public Result<List<GetTotalGroupDayRespDto>> queryDocumentEntryTotalGroupDay(GetTotalGroupDayReqDto req) {
        return Result.success(statisticsQueryHandler.queryDocumentEntryTotalGroupDay(req));
    }

    @Override
    @ApiOperation("获取各类型文档总数以及日增数")
    @GetMapping("/queryDocumentEntryTotalGroupType")
    public Result<List<GetTotalGroupTypeRespDto>> queryDocumentEntryTotalGroupType() {
        return Result.success(statisticsQueryHandler.queryDocumentEntryTotalGroupType());
    }

    @Override
    @ApiOperation("获取各医院文档总数以及日新增数")
    @GetMapping("/queryOrgListGroupOrgName")
    public Result<Page<FindOrgListRespDto>> queryOrgListGroupOrgName(FindOrgListReqDto req) {
        return Result.success(statisticsQueryHandler.queryOrgListGroupOrgName(req));
    }

    @ApiOperation("清文档汇总缓存数据")
    @GetMapping("/clearCache")
    @CacheEvict(value = {"documentSetTotal","documentEntryTotal","documentEntryTotalByDay","documentEntryTotalGroupType"},allEntries = true)
    public Result<Boolean> clearCache(){
        return Result.success(Boolean.TRUE);
    }
}
